<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AtLeast
 *
 * @author Moon
 */
class AtLeast extends CValidator {
    //put your code here
    
    public $required = 1;
    public $arrayAttr = array();
    protected function validateAttribute($object,$attribute) {
        $value=$object->$attribute;
        if(!is_array($value))
            $value = array($value);
        $i=0;
        if(!is_array($this->arrayAttr))
            $this->arrayAttr = array($this->arrayAttr);
        foreach($value as $v) {
            $empty = true;
                foreach($this->arrayAttr as $_a) {
                    if(!empty($v->$_a))
                        $empty = false;
                }
                if(!$empty)
                    $i++;
            
        }
        if($this->required>$i) {
            $message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must have at least more than {required} record.');
            $this->addError($object,$attribute,$message,array('{required}'=>$this->required));
        }
    }
}
?>
